#ifndef __CHANNEL_HPP__
#define __CHANNEL_HPP__
#include <sys/types.h>
#include <unistd.h>
#include<string>

// 管道模块，负责存储写端以及子进程的pid
class Channel
{
public:
    Channel(int fd, pid_t who)
        : _fd(fd), _who(who)
    {
        _name = "Channel-" + std::to_string(fd) + "-" + std::to_string(who);
    }

    ~Channel()
    {}

    int FD()
    {
        return _fd;
    }

    std::string Name()
    {
        return _name;
    }

    void Close()
    {
        ::close(_fd);
    }

    void Send(int cmd)
    {
        ::write(_fd, &cmd, sizeof(cmd));
    }

    pid_t ID()
    {
        return _who;
    }

private:
    int _fd;//管道对应的写端
    pid_t _who;
    std::string _name;
};

#endif